package com.codingfuture.web.controller;

import com.codingfuture.entity.Person;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author kobe
 * @Date 2021/11/5 09:58
 * @Description
 */
@Controller
@RequestMapping("/file")
public class FileController {

    @RequestMapping(value = "/fileUploadAdv", method = RequestMethod.POST)
    public void fileUploadAdv(@RequestParam("f") CommonsMultipartFile file, HttpServletResponse response) throws IOException {
        System.out.println(file.getSize());
        String name = new SimpleDateFormat("yyMMddHHmmssSSSS").format(new Date());
        name += ".jpg";
        //package com.sun.jersey.api.client;
        Client client = Client.create();//
        String filePath = "http://127.0.0.1:8081/imgs/" + name;
        WebResource resource = client.resource(filePath);
        resource.put(file.getInputStream());
        response.getWriter().print(filePath);
    }

}
